package cn.smbms.controller;

import cn.smbms.pojo.RainManage;
import cn.smbms.service.RainManageService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/rainManage")
public class RainManageController {

    private static Logger logger=Logger.getLogger(RainManageController.class);

    @Resource
    private RainManageService rainManageService;

    @RequestMapping(value = "/list")
    public String getqueryAll(Model model){
        List<RainManage> list = rainManageService.queryAll();
        //将信息保存到model中
        if (list != null) {
            model.addAttribute("list", list);
        }
        return "list";
    }

    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String add(@ModelAttribute("rainManage") RainManage rainManage) {//
        logger.info("跳转到新增页面");
        return "add";
    }

    @RequestMapping(value = "/rainManageaddsave", method = RequestMethod.POST)
    public String addSave(RainManage rainManage) {
        try {
            if (rainManageService.add(rainManage)){
                return "redirect:/rainManage/list";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "add";
    }

    @RequestMapping(value = "/del/{id}")
    public String doDel(@PathVariable int id){
        Integer result = rainManageService.del(id);
        return "redirect:/rainManage/list";
    }

}
